/*
 * Population.cpp
 *
 *  Created on: Oct 14, 2014
 *      Author: lfelipe
 */

#include "Population.h"


Population::Population()
{
    individual_default_ = NULL;
}

Population::Population(int population_size, Individual individual_default)
{
    individual_default_ = new Individual(individual_default);

    random_populate(population_size);

}

Population::~Population()
{
    if(individual_default_ !=NULL){
        delete individual_default_;
    }
}

void Population::random_populate(int population_size)  throw(GAQCAException) {

    if(individual_default_ == NULL){
        throw GAQCAException("Default individual not found");
    }

    // CREATE AN RANDOM POPULATION
    for (int i = 0; i < population_size; ++i) {
        individuals_.push_back(*individual_default_);
        individuals_.rbegin()->generate_random_chromosome();
    }

}

const std::vector<Individual>& Population::get_individuals() const
{
    return individuals_;
}

const Individual& Population::get_individual_default() const
{
    return *individual_default_;
}

void Population::set_individual_default(const Individual individualDefault)
{
    *individual_default_ = individualDefault;
}

void Population::set_individuals(const std::vector<Individual>& individuals)
{
    individuals_ = individuals;
}

void Population::clear_population()
{
    individuals_.clear();
}
